package com.ymatou.iapi.sellerproduct.service;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;

public class UpdateStockBySkuCall extends YmatouAutoTestCall{
	private static String opurl ="/api/SellerProduct/UpdateStockBySku";

	
	public UpdateStockBySkuCall() {
		super(EnvSetup.getSystemUrl("sellerproduct_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Content-Type", "application/json");
	}
	
	
	public JSONObject update(int sellerId,Map<String, Object>  skuIdStockMap){
		Map<String,Object> updateMap = new HashMap<>();
		updateMap.put("SellerId", sellerId);
		
		JSONArray skuStockArray = new JSONArray();
		for(String key:skuIdStockMap.keySet()){
			JSONObject ele = new JSONObject();
			try {
				ele.put("SkuId", key);
				ele.put("Num", skuIdStockMap.get(key));
				skuStockArray.put(ele);
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
		}
		
		updateMap.put("SkuStocks", skuStockArray);
		return callAndGetReturnData(updateMap);
		
		
	}
	
	
	
	public static void main(String[] args) {
		new UpdateStockBySkuCall().update(3383,MapUtil.hashMap("111", 123,"222",321));
	}
	
}
